package jdbc;

import java.sql.Connection;
import java.sql.ResultSet;
import java.sql.Statement;

public class JDBCDemo5 {
    public static void main(String[] args) {
        try(
                Connection connection = DBUtil.getConnection();
          ) {
            Statement statement = connection.createStatement();
            String sql = "SELECT s.id,s.name,s.job,c.name,c.floor " +
                    "FROM student s " +
                    "JOIN class c ON s.class_id=c.id " +
                    "WHERE c.name='1年级1班'";
            ResultSet resultSet = statement.executeQuery(sql);
            while (resultSet.next()) {
                int id = resultSet.getInt("id");
                String name = resultSet.getString("name");
                String job = resultSet.getString("job");
                String className = resultSet.getString("name");
                int floor = resultSet.getInt("floor");
                System.out.println(id + " " + name + " " + job + " " + className + " " + floor);
            }

        } catch (Exception e) {
            e.printStackTrace();
        }


    }
}
